using UnityEngine;

public class PlayerStateBehavior_Defense : AbstractPlayerStateBehavior
{
	public static PlayerStateBehavior_Defense instance;

	private PlayerStateBehavior_Defense()
	{
	}

	public static PlayerStateBehavior_Defense getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerStateBehavior_Defense();
		}
		return instance;
	}

	public override void enter(Player owner)
	{
		base.enter(owner);
		if (Random.Range(0, 2) == 0)
		{
			owner.playAnimation(AnimationName.player_defense, 1f, 0.8f);
		}
		else
		{
			owner.playAnimation(AnimationName.player_defense2, 1f, 0.8f);
		}
		if (owner.isBallInHand())
		{
			Instance<Ball>.instance.do_rebound();
		}
	}

	public override void fixedUpdate(Player owner)
	{
		base.fixedUpdate(owner);
		if (owner.teamType == TeamType.COMPUTER || owner != Instance<Court>.instance.teamUser.getPlayer_ControlBall())
		{
			owner.LookAtSmooth(owner.paraPlayer.getPosition());
		}
		if (Instance<Ball>.instance.isInState(BallState_Rebound.getInstance()) && Instance<Ball>.instance.isGetBall(owner.getPosition()))
		{
			Vector3 position = Instance<Ball>.instance.getPosition();
			if (position.y < 1.8f && !Instance<Court>.instance.isInState(CourtStateFreeThrow.getInstance()))
			{
				Instance<Court>.instance.OnGrabedRebound(owner);
			}
		}
	}
}
